package kuti.grp5;

import java.awt.geom.Point2D;
import java.util.List;
import kuti.*;

/**
 * This class is used to store the height of the blades while the simulation
 * runs.
 *
 * @author Marc Schorderet <marc.schorderet@edu.hefr.ch>
 * @author Vincenzo Do <vincenzo.do@edu.hefr.ch>
 * @version 1.0
 *
 * @see ILawn
 */
public class Lawn implements ILawn {

    /*
     * The array that stores the height of the blades
     */
    private int[][] lawn;
    /*
     * The lawnArea of all lawn
     */
    private ILawnArea totalArea;
    /*
     * The parameters of the simulation
     */
    private ISimulParams simulParams;

    /**
     * Constructor of the class Lawn, we start by creating the array with the
     * dimension of the world. A lawnArea which represents all the Lawn is
     * created.
     *
     * @param simulParams the parameters of the simulation
     */
    public Lawn(ISimulParams simulParams) {
        if(simulParams == null){
            throw new IllegalArgumentException("the parameters of the simulation are not defined");
        }

        this.simulParams = simulParams;
        lawn = new int[SimulParams.WORLD_HEIGHT][SimulParams.WORLD_WIDTH];

        Point2D.Double from = new Point2D.Double(0.0, 0.0);
        Point2D.Double to = new Point2D.Double(SimulParams.WORLD_WIDTH, SimulParams.WORLD_HEIGHT);

        totalArea = new LawnArea(from, to, lawn, simulParams);

    }

    /**
     *
     * @return Returns the height of blade of grass.
     */
    @Override
    public ILawnArea getBladeHeight() {
        return totalArea;
    }

    /**
     *
     * @param formX X value
     * @param formY Y value
     * @param zoneWidth widht of the zone
     * @param zoneHeight height of the zone
     *
     * @return Returns the lawn area for the specified rectangular zone.
     *
     */
    @Override
    public ILawnArea getLawnHeight(int fromX, int fromY, int zoneWidth,
            int zoneHeight) {

        Point2D from = new Point2D.Double(fromX, fromY);
        Point2D to = new Point2D.Double(fromX + zoneWidth, fromY + zoneHeight);

        return new LawnArea(from, to, lawn, simulParams);

    }

    /**
     *
     * @return returns the lawn
     */
    public int[][] getLawn() {
        return lawn;
    }
}
